﻿Public Class Location
    Private _Exist As Boolean = False
    ReadOnly Property exist() As Boolean
        Get
            Return _Exist
        End Get
    End Property
    Private _key As String
    ReadOnly Property key() As String
        Get
            Return _key
        End Get

    End Property


    Private _city As String

    Public ReadOnly Property city() As String
        Get
            Return _city
        End Get

    End Property
    Private _state As String
    Public ReadOnly Property state() As String
        Get
            Return _state
        End Get

    End Property
    Private _country As String
    Public ReadOnly Property country() As String
        Get
            Return _country
        End Get
    End Property
    Sub New(ByVal attendee As Outlook.Recipient)
        Dim pAcc As Outlook.PropertyAccessor

        Dim exUser As Outlook.ExchangeUser
        Dim found As Boolean = False
        Dim cs As String = Nothing

        exUser = attendee.AddressEntry.GetExchangeUser
        If Not (exUser Is Nothing) Then
            found = False
            'todo: determine if we should also use country as part of location
            pAcc = exUser.PropertyAccessor
            Try
                _country = pAcc.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x3A26001E")
            Catch expAcc As Exception
                _country = ""
            End Try
            _city = exUser.City
            _state = exUser.StateOrProvince
            cs = exUser.City & ", " & exUser.StateOrProvince & ", " & country
        Else
            Dim attendeeContact As Outlook.ContactItem

            attendeeContact = attendee.AddressEntry.GetContact()
            If attendeeContact Is Nothing Then
                cs = ""
            Else
                _city = attendeeContact.BusinessAddressCity
                _state = attendeeContact.BusinessAddressState
                _country = attendeeContact.BusinessAddressCountry
                cs = attendeeContact.BusinessAddressCity & ", " & attendeeContact.BusinessAddressState & ", " & attendeeContact.BusinessAddressCountry
            End If
            found = False

        End If
        _key = cs
        If (_city = "") And (_country = "") And (_state = "") Then
            _Exist = False
        Else
            _Exist = True
        End If
    End Sub
End Class
